﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;

namespace OnlineShop
{
    /// <summary>
    /// Interaction logic for RegisterShop.xaml
    /// </summary>
    public partial class RegisterShop : Window
    {
        public RegisterShop()
        {
            InitializeComponent();
        }

        private void OnAddShopClick(object sender, RoutedEventArgs e)
        {
            Shop currShop = new Shop("ime");
            this.name.Text = this.name.Text.Trim();
            this.password.Password = this.password.Password.Trim();
            try
            {
                currShop.Name = this.name.Text;
                currShop.Password = this.password.Password;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            if (File.Exists("Shops\\" + currShop.Name + ".txt"))
            {
                MessageBox.Show(string.Format("Shop {0} already exists", currShop.Name));
                return;
            }

            StreamWriter writer = new StreamWriter("Shops\\" + currShop.Name + ".txt");

            using (writer)
            {
                writer.WriteLine("Name:{0}:", currShop.Name);
                writer.WriteLine("Password:{0}:", currShop.Password);
                MessageBox.Show("Registered Successfully");
            }
        }

        private void OnBackToMainMenuClick(object sender, RoutedEventArgs e)
        {
            StartMenu window = new StartMenu();
            window.Show();
            this.Close();
        }
    }
}
